package cn.momoshenchi.controller;

import cn.momoshenchi.pojo.Article;
import cn.momoshenchi.pojo.Book;
import cn.momoshenchi.service.SearchService;
import cn.momoshenchi.util.AssertUtil;
import cn.momoshenchi.util.ResultInfo;
import cn.momoshenchi.service.ArticleService;
import cn.momoshenchi.service.BookService;
import cn.momoshenchi.vo.SearchVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * @version : 1.0
 * @author: momoshenchi
 * @date: 2021/6/8 - 9:50
 */
@RestController
@RequestMapping("search")
public class SearchController
{


    @Autowired
    private SearchService searchService;


    @GetMapping("{keyword}")
    @Operation(summary = "根据关键词搜索book和article")
    public ResultInfo random(@PathVariable String keyword) throws IOException, InvocationTargetException, IllegalAccessException
    {
        AssertUtil.isTrue(keyword==null,"关键词不能为空");
        SearchVo searchVo=searchService.searchArticleAndBook(keyword);
        return  new ResultInfo(searchVo);
    }

}
